@section('title', '用户编辑')
@section('content')
    <div class="layui-form-item">
        <label class="layui-form-label">标题：</label>
        <div class="layui-input-block">
            <input type="text" value="{{$info->title or ''}}" name="title" required lay-verify="user_name" placeholder="标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">副标题：</label>
        <div class="layui-input-block">
            <input type="text" value="{{$info->sorttitle or ''}}" name="title" required lay-verify="sorttitle" placeholder="副标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图片上传：</label>
        <div class="layui-input-block">
          <input type="file" name="img" class="layui-upload-file">
            <p>
                <img id="imagesurl" src="" width="100px" height="100px">
            </p>
            <input type="hidden" id="img" value="{{$info->img or ''}}" name="img" required lay-verify="user_name" placeholder="图片" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">价格：</label>
        <div class="layui-input-block">
            <input type="number" value="{{$info->price or ''}}" name="price" required  placeholder="价格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">佣金：</label>
        <div class="layui-input-block">
            <input type="number" value="{{$info->commission or ''}}" name="commission" required  placeholder="佣金" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">栏目菜单：</label>
        <div class="layui-input-block">
            <select name="menu_id" lay-verify="required">
                <option value=""></option>
                @foreach($menu as $val)
                    <option value="{{$val['menu_id']}}">
                        {{$val['name']}}
                    </option>
                @if(isset($val['child']))
                        @foreach ($val['child'] as $c)
                            <option value="{{$c['menu_id']}}">
                                ├─{{$c['name']}}
                            </option>
                        @endforeach
                    @endif

                    @endforeach
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容：</label>
        <div class="layui-input-block">
            <textarea id="demo" name="content" style="display: none;"></textarea>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">起始时间：</label>
        <div class="layui-input-block">
            <input type="text" name="setime" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最新线路</label>
        <div class="layui-input-block">
            <input type="checkbox"  name="newest" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">高佣金线路</label>
        <div class="layui-input-block">
            <input type="checkbox" name="highcommission" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">热销线路</label>
        <div class="layui-input-block">
            <input type="checkbox" name="sellwell" lay-skin="switch">
        </div>
    </div>
@endsection
@section('id',$id)
@section('js')
    <script>
        layui.use(['form','jquery','laypage', 'layer','layedit','upload'], function() {
            var form = layui.form(),
                $ = layui.jquery;
            form.render();
            var layer = layui.layer;
            var layedit = layui.layedit;
            layedit.build('demo'); //建立编辑器
             upload = layui.upload;

            //普通图片上传
            layui.upload({
                url: '/content/upload'

                ,success: function(res){
                    if(res.code=='200'){
                        $("#img").val('/uploads/'+res.imgurl);
                        $("#imagesurl").attr('src','/uploads/'+res.imgurl);
                        layer.msg(res.msg, {time: 1000});
                        console.log(res.msg); //上传成功返回值，必须为json格式
                    }else{
                        layer.msg(res.msg, {time: 1000});
                    }

                }
            });

            form.on('submit(formDemo)', function(data) {
                $.ajax({
                    url:"{{url('/content')}}",
                    data:$('form').serialize(),
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        if(res.status == 1){
                            layer.msg(res.msg,{icon:6});
                            var index = parent.layer.getFrameIndex(window.name);
                            setTimeout('parent.layer.close('+index+')',2000);
                        }else{
                            layer.msg(res.msg,{shift: 6,icon:5});
                        }
                    },
                    error : function(XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg('网络失败', {time: 1000});
                    }
                });
                return false;
            });
        });
    </script>
@endsection
@extends('common.edit')